/*
 * @Description: Store
 * @Author: seadon
 * @LastEditors: seadon
 * @Date: 2022-03-09 10:24:53
 * @LastEditTime: 2022-03-30 13:46:57
 */
import { createStore } from 'vuex'
import { i18n, LocaleEnum } from '@/locales'
import { imAll } from '@/constant/login'
export default createStore({
	state: {
		// 用户信息
		userInfo: { phone: '', employee_id: '', has_set_pwd: true },
		// 租户信息
		tenant: { env_type: '', tenant_auth: { baiteda_security_account: '' } },
		// 菜单是否收起
		collapsed: false,
		// 收藏数量
		collectNumber: 0,
		taskCount: {
			apply: 0,
		},
		imAll: [...imAll],
		//首页右侧菜单是否展示
		showVideo: false,
		centerUser: { user_base_info: {} },
		Drafts: { total: 0, data: [] },
		TodoTask: { total: 0, data: [] },
		DoneTask: { total: 0, data: [] },
		bidDoneTask: { total: 0, data: [] },
		AgentDoneTask: { total: 0, data: [] },
		ExpactTask: { total: 0, data: [] },
		AgentTodo: { total: 0, data: [] },
		Apply: { total: 0, data: [] },
		TaskNotice: { total: 0, data: [] },
		AgentNotice: { total: 0, data: [] },
		// 外部注册列表
		outsideOrgRegisterListDeptList: [], // 外部组织--用户注册列表
		outsideOrgRegisterListDeptTypeList: [], // 外部组织--组织注册列表
		//结束新版本提示状态
		showNewVersionTipsEnd: false,
		//结束快速掌握“百特搭”使用方式
		showUserGuideEnd: false,
		// 外部组织列表储存方便个人中心和门户公用
		outsideOrgList: [],
		//是否是筛选页面
		issx: false,
		// 新版移动端
		// mobileFront: {
		// 	myTaskActiveTab: 'toDo',
		// },
		isShowPwd: false,
		showPwdType: 0,
		org_pwd_has_set: true,
		firterAfterDate: { DoneTask: {} },
		activeProcessKey: 'TodoTask',
	},
	mutations: {
		setActiveProcessKey(state, payload) {
			state.activeProcessKey = payload
		},
		setUserInfo(state, payload) {
			// 如果是英文情况下，使用en的名称
			if (i18n.locale === LocaleEnum.en) {
				if (payload.employee_en_name)
					payload.employee_name = payload.employee_en_name
				payload.manage_dept_name = payload.manage_dept_en_name
				payload.belong_dept_name = payload.belong_dept_en_name
			}
			state.userInfo = payload
		},
		setShowVideo(state, payload) {
			state.showVideo = payload
		},
		setFirterAfterDate(state, payload) {
			if (payload.taskType === 'DoneTask') {
				state.firterAfterDate.DoneTask[payload.doneType] = payload.checkedValue
			} else {
				state.firterAfterDate[payload.taskType] = payload.checkedValue
			}
		},
		SET_SHOW_VERSION_TIPS_END(state, payload) {
			state.showNewVersionTipsEnd = payload
		},
		SET_USER_GUIDE_END(state, payload) {
			state.showUserGuideEnd = payload.status
			payload.isShowPwd && (state.isShowPwd = payload.isShowPwd)
		},
		setTenant(state, payload) {
			state.tenant = payload
			if (payload.login_types.split(',').includes('20')) {
				const imgType = payload.login_types
					.split(',')
					.filter((item: string) => {
						return item !== '0'
					})[0]
				const imAllObj = {
					name: payload[
						`custom_login_icon_title_${localStorage
							.getItem('locale')
							?.slice(0, 2)}`
					],
					imgName: payload.custom_login_icon,
					type: imgType,
				}
				state.imAll.push(imAllObj)
			}
		},
		setCollapsed(state, payload) {
			state.collapsed = payload
		},
		setIssx(state, payload) {
			state.issx = payload
		},
		setCollectNumber(state, payload) {
			state.collectNumber = payload
		},
		setTaskCount(state, payload) {
			state.taskCount = payload
		},
		// setImAll(state, payload) {
		// 	const imgType = payload.data.login_types
		// 		.split(',')
		// 		.filter((item: string) => {
		// 			return item !== '0'
		// 		})[0]
		// 	const imAllObj = {
		// 		name: '自定义',
		// 		imgName: payload.data.custom_login_icon,
		// 		type: imgType,
		// 	}
		// 	state.imAll.push(imAllObj)
		// },
		setCenterUser(state, payload) {
			state.centerUser = payload
		},
		setOutsideOrgRegisterList(state, payload) {
			state.outsideOrgRegisterListDeptList = payload.register_user_list
			state.outsideOrgRegisterListDeptTypeList = payload.register_dept_list
		},
		setOutsideOrgList(state, payload) {
			state.outsideOrgList = payload
		},
		// // 储存新版移动端我的任务activeTab
		// setMyTaskActiveTab(state, payload) {
		// 	state.mobileFront.myTask?ActiveTab = payload
		// },
	},
	actions: {},
	modules: {},
})
